package com.shu.map;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/7/29 16:59
 */

public class HashMapNotSafe {


    public static void main(String[] args) {
        final Map<Integer,String> map = new HashMap();
        final Integer targetKey = 65535; // 65535
        final String targetVal = "v";
        map.put(targetKey,targetVal);


        new Thread(()->{
            IntStream.range(0,targetKey).forEach(k->map.put(k,"v"));
        }).start();

        LongAdder longAdder = new LongAdder();
        while (true){
            longAdder.increment();
            if (null == map.get(targetKey)){
                System.out.println("invoke - " + longAdder.intValue());
                throw new RuntimeException("HashMap is not safe");
            }
        }

    }
}
